package cn.xunjie.ymcc.web.controller;

import cn.xunjie.ymcc.dto.RegisterDto;
import cn.xunjie.ymcc.exception.GlobalException;
import cn.xunjie.ymcc.feignClients.UserFeignClient;
import cn.xunjie.ymcc.result.JSONResult;
import cn.xunjie.ymcc.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
public class VerifycodeController {
    @Autowired
    private IVerifyCodeService verifyCodeService;

    @GetMapping("/verifycode/imageCode/{imageCodeKey}")
    public JSONResult imageCode(@PathVariable("imageCodeKey") String key){
        if(StringUtils.isEmpty(key)){
            new GlobalException("不对");
        }


        String base64Str = verifyCodeService.imageCode(key);
        return JSONResult.success(base64Str);

    }
    @PostMapping("/verifycode/sendSmsCode")
    public JSONResult sendSmsCode(@RequestBody RegisterDto dto){
        if(StringUtils.isEmpty(dto)){
            new GlobalException("不能为空");
        }
        try {
            verifyCodeService.sendSmsCode(dto);
            return JSONResult.success();
        } catch (GlobalException e) {
            e.printStackTrace();
            return JSONResult.error(e.getMessage());
        }
    }
}
